home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0094_Faster Sprites.pas < prev    next >
Pascal/Delphi Source File  |  1994-05-25  |  4KB  |  227 lines

  1. {
  2.   For the people who requested a faster sprite drawing program, here it is.
  3. This program is just Bas van Gaalen's sprite program with a few modifications
  4. to make it run quicker.  I am currently working on this program, so that it
  5. will be able to handle more sprites than one..
  6.  
  7. ------------------- CUT HERE ----------------------
  8. }
  9.  
  10. PROGRAM Game_sprites;
  11. { By Bas van Gaalen, Holland, PD }
  12. {$G+}
  13.  
  14. USES crt;
  15.  
  16. CONST w=16; h=16; sega000= $0A000;
  17.  
  18. TYPE
  19.   SPRBUF = Array[1..256] of Byte;
  20.  
  21. VAR
  22.   Bckbuf,Sprite : SPRBUF;
  23.   px,py : Word;
  24.   CCOS,CSIN : Array [0..360] of WORD;
  25.  
  26. CONST
  27.   SegS : Word = SEG(Sprite);
  28.   OfsS : Word = OFS(Sprite);
  29.   SegB : Word = SEG(BckBuf);
  30.   OfsB : Word = OFS(BckBuf);
  31.  
  32.  
  33. PROCEDURE setpal(col,r,g,b : byte); assembler;
  34. ASM
  35.   mov dx,03c8h
  36.   mov al,col
  37.   out dx,al
  38.   inc dx
  39.   mov al,r
  40.   out dx,al
  41.   mov al,g
  42.   out dx,al
  43.   mov al,b
  44.   out dx,al
  45. END;
  46.  
  47. PROCEDURE retrace; assembler;
  48. ASM
  49.   mov  dx,03dah
  50. @l2:
  51.   in   al,dx
  52.   test al,8
  53.   jz   @l2
  54. END;
  55.  
  56. PROCEDURE putsprite(x,y:word);
  57. BEGIN
  58.   ASM
  59.     CLI
  60.     PUSH DS
  61.     MOV  AX,0A000h
  62.     MOV  ES,AX
  63.     MOV  DS,SegB
  64.     MOV  AX,PY
  65.     SHL  AX,6
  66.     MOV  DI,AX
  67.     SHL  AX,2
  68.     ADD  DI,AX
  69.     ADD  DI,PX
  70.     MOV  DX,1010h
  71.     MOV  AX,OfsB
  72.     MOV  SI,AX
  73.     XOR  AX,AX
  74. @1:
  75.     MOV  AL,[DS:SI]     { Display the sprite buffer over the old sprite }
  76.     MOV  [ES:DI],AL
  77.     INC  DI
  78.     INC  SI
  79.     DEC  DL
  80.     JNZ  @1
  81.     ADD  DI,304
  82.     MOV  DL,16
  83.     DEC  DH
  84.     JNZ  @1
  85.     MOV  AX,Y
  86.     SHL  AX,6
  87.     MOV  DI,AX
  88.     SHL  AX,2
  89.     ADD  DI,AX
  90.     ADD  DI,X
  91.     MOV  DX,1010h
  92.     MOV  AX,OfsB
  93.     MOV  SI,AX
  94.     XOR  AX,AX
  95. @2:                           { Store the background into the Sprite Buffer }
  96.     MOV  AL,[ES:DI]
  97.     MOV  [DS:SI],AL
  98.     INC  DI
  99.     INC  SI
  100.     DEC  DL
  101.     JNZ  @2
  102.     ADD  DI,304
  103.     MOV  DL,16
  104.     DEC  DH
  105.     JNZ  @2
  106.     MOV  AX,Y
  107.     SHL  AX,6
  108.     MOV  DI,AX
  109.     SHL  AX,2
  110.     ADD  DI,AX
  111.     ADD  DI,X
  112.     MOV  DX,1010h
  113.     MOV  AX,OfsS
  114.     MOV  SI,AX
  115.     XOR  AX,AX
  116. @3:
  117.     CMP  [DS:SI],AH      { Display the Sprite at it's new location }
  118.     JZ   @4
  119.     MOV  AL,[DS:SI]
  120.     MOV  [ES:DI],AL
  121. @4:
  122.     INC  DI
  123.     INC  SI
  124.     DEC  DL
  125.     JNZ  @3
  126.     ADD  DI,304
  127.     MOV  DL,16
  128.     DEC  DH
  129.     JNZ  @3
  130.     POP  DS
  131.     STI
  132.   END;
  133.   px:=x; py:=y;
  134. END;
  135.  
  136. (* This procedure I added to speed up the rotation used when displaying the
  137. sprite.  This is not nessary, but usefull *)
  138.  
  139. PROCEDURE Calc_Cos_Sin;
  140. VAR I : word;
  141. BEGIN
  142.   FOR I := 0 to 360 DO
  143.   BEGIN
  144.     CCOS[I] := ROUND(COS(PI*I/180)*150);
  145.     CSIN[I] := ROUND(SIN(PI*I/180)*75);
  146.   END;
  147. END;
  148.  
  149. var i,j:word;
  150.  
  151. BEGIN
  152.   ASM
  153.     mov ax,13h
  154.     int 10h
  155.   END;
  156.   Calc_Cos_Sin;
  157.   for i:=1 to 255 do setpal(i,255-i div 6,255-i div 4,20);
  158.   fillchar(bckbuf,sizeof(bckbuf),0);
  159.   { create background }
  160.   for i:=0 to 319 do
  161.     for j:=0 to 199 do
  162.       mem[sega000:j*320+i]:=round(5+0.4*i+0.4*j)+random(10);
  163.   { create random sprite }
  164.   randomize;
  165.   for i:=1 to 256 do
  166.     sprite[i]:=random(255);
  167.   { clear middle part }
  168.   for i:=6 to 10 do
  169.     for j:=6 to 10 do
  170.       sprite[j*w+i]:=0;
  171.   i:=0;
  172.   { save first old backup screen }
  173.   px:=0; py:=0;
  174.  
  175. (*  The following assembly code is required to save the sprites background when
  176. it is first displayed.  I am still trying to figure how to incorperate this
  177. into the main assembly code for displaying the sprite *)
  178.  
  179.   ASM
  180.     CLI
  181.     PUSH BP
  182.     PUSH DS
  183.  
  184.     MOV  AX,SegA000
  185.     MOV  ES,AX
  186.     MOV  DS,SegB
  187.  
  188.     MOV  AX,0
  189.     SHL  AX,6
  190.     MOV  DI,AX
  191.     SHL  AX,2
  192.     ADD  DI,AX
  193.     ADD  DI,0
  194.  
  195.     MOV  DX,1010h
  196.     MOV  AX,OfsB
  197.     MOV  BP,AX
  198.     XOR  AX,AX
  199. @2:
  200.     MOV  AL,[ES:DI]
  201.     MOV  [DS:BP],AL
  202.     INC  DI
  203.     INC  BP
  204.     DEC  DL
  205.     JNZ  @2
  206.     ADD  DI,304
  207.     MOV  DL,16
  208.     DEC  DH
  209.     JNZ  @2
  210.  
  211.     POP  DS
  212.     POP  BP
  213.     STI
  214.   END;
  215.   { move sprite over background }
  216.   repeat
  217.     retrace;
  218.     putsprite(150+CCOS[I],100+CSIN[I]);
  219.     i:=1+i mod 360;
  220.   until keypressed;
  221.   ASM
  222.     mov ax,3h
  223.     int 10h
  224.   END;
  225. END.
  226.  
  227.